package com.zmytest.service.impl;

import com.zmytest.service.CookieService;
import com.zmytest.util.SecretUtil;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

/**
 * Created on 2018/12/14.
 *
 * @author zhangmingyu
 */
@Service
public class CookieServiceImpl implements CookieService {
    @Override
    public void create(String key, String value) {
        String secretValue = SecretUtil.encryptDes(value);
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletResponse response = attributes.getResponse();
        response.addCookie(new Cookie(key,secretValue));
    }
}
